/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-08-15
 * Time: 0:13
 */
//https://leetcode.cn/problems/happy-number/
public class Test {
    public static int fun(int n){
        int sum=0;
        int x;
        while(n>0){
            x=n%10;
            n=n/10;
            sum=sum+x*x;
        }
        return sum;
    }
    public static boolean isHappy(int n) {
        int p1=n;
        int p2=fun(n);
        while(p1!=p2){
            p1=fun(p1);
            p2=fun(p2);
            p2=fun(p2);
        }
        if(p1==1){
            return true;
        }
        else{
            return false;
        }
    }
    public static void main(String[] args) {
        System.out.println(isHappy(2));
    }
}
